﻿using System;
using System.Runtime.Serialization;
using System.Xml.Linq;

namespace NCMIS.ObjectModel.MetaData
{
    /// <summary>
    /// Represents a ID object-type property definition.
    /// </summary>
    [DataContract(Name = "propertyIdDefinition", Namespace = CmisNs.Cmis)]
    public class PropertyIdDefinition : PropertyDefinition
    {
        /// <summary>
        /// The value that the repository must set for the property if a value is not provided by an
        /// application when the object is created. If no default value is specified and an application
        /// creates an object of this type without setting a value for the property, the repository
        /// must attempt to store a "value not set" state for the property value. If this occurs for a
        /// property that is defined to be required, then the creation attempt must throw an exception.
        /// The attributes on the default value element are the same as the attributes on the property
        /// definition. 
        /// </summary>
        [DataMember(Name = "defaultValue")]
        public CmisPropertyId DefaultValue
        {
            get;
            set;
        }

        /// <summary>
        /// Indicates an explicit ordered set of values allowed for this property. If this attribute is
        /// "not set", then any valid value for this property based on its type may be used. Each choice
        /// includes a displayName and a value. The displayName is used for presentation purpose. The
        /// value will be stored in the property when selected. Choices may be hierarchically presented.
        /// </summary>
        [DataMember(Name = "choice")]
        public CmisChoiceId[] Choice
        {
            get;
            set;
        }

        public override XElement ToXElement()
        {
            XNamespace ns = CmisNs.Cmis;
            return new XElement(ns + "propertyIdDefinition",
                new XElement(ns + "id", this.Id),
                new XElement(ns + "localName", this.LocalName),
                new XElement(ns + "localNameSpace", this.LocalNamespace),
                new XElement(ns + "displayName", this.DisplayName),
                new XElement(ns + "queryName", this.QueryName),
                new XElement(ns + "description", this.Description),
                new XElement(ns + "propertyType", this.PropertyType.ToString().ToLower()),
                new XElement(ns + "cardinality", this.Cardinality.ToString().ToLower()),
                new XElement(ns + "updatability", this.Updatability.ToString().ToLower()),
                new XElement(ns + "inherited", this.Inherited.ToString().ToLower()),
                new XElement(ns + "required", this.Required.ToString().ToLower()),
                new XElement(ns + "queryable", this.Queryable.ToString().ToLower()),
                new XElement(ns + "orderable", this.Orderable.ToString().ToLower()),
                new XElement(ns + "openChoice", this.OpenChoice.ToString().ToLower()));
        }
    }
}
